<%--
  Created by IntelliJ IDEA.
  User: RE1UY
  Date: 2021/10/13
  Time: 8:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>购物车</title>
    <script src="/reiCode/js/jquery-3.5.1.js" type="text/javascript"></script>
    <script>
        function deletegoodincart(cartid) {
            if (confirm("您确定要将此商品移出购物车吗?")) {
                $.ajax({
                    url: "${pageContext.request.contextPath}/cart/deletecart.do",
                    type: "get",
                    dataType: "text",
                    data: {"cartid": cartid},
                    success: function (msg) {
                        alert(msg);
                        location.reload();
                    }

                })
            }
        }

        function buygoodnow(cartid) {
            if (confirm("您确定要购买该商品吗?")) {
                window.location.href = "${pageContext.request.contextPath}/transaction/creattransactionfromcart.do?cartid=" + cartid
            }
        }
    </script>
</head>
<body>
<center>
    <table border="1">
        <tr>
            <th>商品id</th>
            <th>商品名称</th>
            <th>商品价格</th>
            <th>商品介绍</th>
            <th>商品分类</th>
            <th>商品数量</th>
            <th>商品总价</th>
            <th>商品状态</th>
            <th>移出购物车</th>
            <th>购买</th>
        </tr>
        <c:forEach items="${carts}" var="g">
            <tr>
                <td>${g.goodid}</td>
                <td>${g.goodname}</td>
                <td>${g.goodprice}</td>
                <td>${g.goodintro}</td>
                <td>${g.goodtag}</td>
                <td>${g.quantity}</td>
                <td>//TODO</td>
                <td>${g.state}</td>
                <td><input type="button" value="移出购物车" onclick="deletegoodincart(${g.cartid})"></td>
                <td><input type="button" value="购买" onclick="buygoodnow(${g.cartid})"></td>
            </tr>
        </c:forEach>
    </table>
</center>
</body>
</html>
